package com.demarc.pesquisas.web.converter;

import javax.faces.convert.FacesConverter;

import org.joda.time.DateTime;
import org.joda.time.LocalTime;

@FacesConverter(value = "LocalTimeConverter", forClass = LocalTime.class)
public class LocalTimeConverter extends AbstractJodaTimeConverter {
	/**
	 * {@inheritDoc}
	 */
	@Override
	protected String getPattern() {
		return "HH:mm";
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected Object getAsObject(DateTime dateTime) {
		LocalTime time = null;

		if (dateTime != null) {
			time = dateTime.toLocalTime();
		}
		return time;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected String getAsString(Object object) {
		return ((LocalTime) object).toString(getPattern());
	}
}
